package com.ddlaw.utils;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
/**
 * Xml解析（读取学校）
 * @author YunLong
 *
 */
@SuppressWarnings("all")
public class XmlReadUtil {
	/**
	 * 读取全部内容
	 * @param path	文件路径
	 * @param c
	 * @return
	 */
	public static Map<String,String> read(String path,Class c){
		Map<String,String> result = new LinkedHashMap<String, String>();
		SAXReader reader = new SAXReader();   
		Document doc;  
	    ClassLoader classLoader=c.getClassLoader();  
	    InputStream in=classLoader.getResourceAsStream(path);  
	    try {
			doc = reader.read(in);
			Element root = doc.getRootElement();  
			for(Iterator it=root.elementIterator();it.hasNext();){     
		        Element element = (Element) it.next();       
		        String id = element.elementText("id");
		        String name = element.elementText("name");
		       result.put(id, name);
		 }  
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
	    return result;
	}
}
